/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package carrello.impl.boundary.user;

import carrello.impl.boundary.AbstractUI;
import carrello.impl.controller.user.LogInCTRL;
import org.apache.log4j.Logger;

/**
 *
 * @author mepcotterell
 */
public class LogInUI extends AbstractUI{
    
    private String username = null;
    private String password = null;
    Logger log = Logger.getLogger(LogInUI.class);
    @Override
    public String execute() {       
        
        if (getSessionIsLoggedIn()) {
            return ERROR;
        }
        String role;
        if (username != null) {
            if ((role = LogInCTRL.login(username, password)) != null ) {
                setSessionIsLoggedIn(true);
                setSessionUsername(username);
                
                setSessionRole(role);
                log.info(getSessionRole());
                return SUCCESS;
            } else {
                return ERROR;
            }
        }
        
        return INPUT;   
    }
    
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
    
}
